package com.scgl.suppliers.controller;

import java.util.Date;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.scgl.suppliers.domain.SuppliersType;
import com.scgl.suppliers.service.ISuppliersTypeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 分类Controller
 *
 * @author mobai
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/type")
public class SuppliersTypeController extends BaseController
{
    @Autowired
    private ISuppliersTypeService suppliersTypeService;

    /**
     * 查询分类列表
     */
    @RequiresPermissions("suppliers:type:list")
    @GetMapping("/list")
    public TableDataInfo list(SuppliersType suppliersType)
    {
        startPage();
        List<SuppliersType> list = suppliersTypeService.selectSuppliersTypeList(suppliersType);
        return getDataTable(list);
    }

    /**
     * 导出分类列表
     */
    @RequiresPermissions("suppliers:type:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SuppliersType suppliersType)
    {
        List<SuppliersType> list = suppliersTypeService.selectSuppliersTypeList(suppliersType);
        ExcelUtil<SuppliersType> util = new ExcelUtil<SuppliersType>(SuppliersType.class);
        util.exportExcel(response, list, "分类数据");
    }

    /**
     * 获取分类详细信息
     */
    @RequiresPermissions("suppliers:type:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(suppliersTypeService.selectSuppliersTypeById(id));
    }

    /**
     * 新增分类
     */
    @RequiresPermissions("suppliers:type:add")
    @PostMapping
    public AjaxResult add(@RequestBody SuppliersType suppliersType)
    {
        suppliersType.setCreateDate(new Date());
        suppliersType.setCreateName("张三");
        return toAjax(suppliersTypeService.insertSuppliersType(suppliersType));
    }

    /**
     * 修改分类
     */
    @RequiresPermissions("suppliers:type:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody SuppliersType suppliersType)
    {
        return toAjax(suppliersTypeService.updateSuppliersType(suppliersType));
    }

    /**
     * 删除分类
     */
    @RequiresPermissions("suppliers:type:remove")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(suppliersTypeService.deleteSuppliersTypeByIds(ids));
    }
}
